package com.geeksaga.enums;

/**
 * @author newbie
 * @since 0.1
 */
public enum HtmlTags {
	HR(Tag.hr),
	BR(Tag.br),
	UL(Tag.ul),
	OL(Tag.ol),
	LI(Tag.li),
	LINK(Tag.link);
	
	private Tag tag;
	private static final String TAG_HR = "hr";
	private static final String TAG_BR = "br";
	private static final String TAG_UL = "ul";
	private static final String TAG_OL = "ol";
	private static final String TAG_LI = "li";
	private static final String TAG_LINK = "a";
	
	HtmlTags(Tag tag) {
		this.tag = tag;
	}
	
	private enum Tag {
		hr {
			String getTagName() {
				return TAG_HR;
			}
			
			String getTag() {
				return "<hr />";
			}
			
			public String regex() {
				return "(^|\n)\\s*----\\s*(\n|$)";
			}
		},
		
		br {
			String getTagName() {
				return TAG_BR;
			}
			
			String getTag() {
				return "<br />";
			}
			
			public String regex() {
				return "\\\\";
			}
		},
		
		ul {
		    String getTagName() {
		        return TAG_UL;
		    }
		    
		    String getTag() {
		        return "<ul>";
		    }
		    
		    public String regex() {
		        return "/(^|\n)([ \t]*\\*[^*#].*(\n|$)([ \t]*[^\\s*#].*(\n|$))*([ \t]*[*#]{2}.*(\n|$))*)+/";
		    }
		},
		
		ol {
		    String getTagName() {
		        return TAG_OL;
		    }
		    
		    String getTag() {
		        return "<ol>";
		    }
		    
		    public String regex() {
		        return "/(^|\n)([ \t]*#[^*#].*(\n|$)([ \t]*[^\\s*#].*(\n|$))*([ \t]*[*#]{2}.*(\n|$))*)+/";
		    }
		},
		
		li {
		    String getTagName() {
		        return TAG_LI;
		    }
		    
		    String getTag() {
		        return "'$1'";
		    }
		    
		    public String regex() {
		        return "/[ \t]*([*#]).+(\n[ \t]*[^*#\\s].*)*(\n[ \t]*\1[*#].+)*/";
		    }
		},
		
		link {
		    String getTagName() {
		        return TAG_LINK;
		    }
		    
		    String getTag() {
		        return "<a href='$1'>$2</a>";
		    }
		    
		    public String regex() {
		        return "\\[\\[([^\\]|~\\n]*(?:(?:\\](?!\\])|~.)[^\\]|~\\n]*)*)\\|([^\\]~\\n]*(?:(?:\\](?!\\])|~.)[^\\]~\\n]*)*)\\]\\]";
		    }
		};
		
		abstract String getTagName();
		
		abstract String getTag();
		
		abstract String regex();
	}
	
	public String getTagName() {
		return tag.getTagName();
	}
	
	public String getTag() {
		return tag.getTag();
	}
	
	public String regex() {
		return tag.regex();
	}
}